import {makeAutoObservable} from "mobx";

class TaskStore {

    list=[
        {id:1,name:"JAVA",isDone:true},
        {id:2,name:"Python",isDone:true},
        {id:3,name:"C语言",isDone:true},
        {id:4,name:"C++",isDone:false}
    ]
   // 全选或者全不选操作
   selectAll=(checked)=>{
       this.list.forEach(item => {
           item.isDone = checked
       });
    }
    //计算属性
    get isAll() {
        return this.list.every(item=>item.isDone)
    }

    //单选操作
    checkIsDone(id,isDone){
     const item=  this.list.find(item=>item.id===id)
        item.isDone=isDone
    }
    //删除操作
    deleteTask(id) {

       this.list= this.list.filter(item=>item.id !== id)
    }
    //新增Task
    addTask(task) {
        this.list.push(task)
    }

    constructor() {
        makeAutoObservable(this)
    }
}

export default TaskStore;